/*-------------------------------------------------------
-   文件名：lexical.h
-     模块：lexical
-     作用：词法分析部分使用的数据结构，和对这个数据结构
            的操作函数。
            主要是状态机, 这是 lexical 第二版.
-     版本：
-------------------------------------------------------*/

#ifndef  _LEXICAL2_H_
#define  _LEXICAL2_H_

#include  "asmtype.h"
#include  "character.h"
#include  "input.h"



#define   LEX_TK_ERROR    (0)     /* error */
#define   LEX_TK_COMMAND  (1)     /**/
#define   LEX_TK_GREG     (2)
#define   LEX_TK_ALPHA    (3)

#define   LEX_TK_LABLE    (4)
#define   LEX_TK_SREG     (5)
#define   LEX_TK_INSTRUCT (6)
#define   LEX_TK_CONST    (7)     /**/

#define   LEX_TK_INTEGER  (8)
#define   LEX_TK_FLOAT    (9)
#define   LEX_TK_STRING   (10)

#define   LEX_TK_COLON    (11)
#define   LEX_TK_COMMA    (12)
#define   LEX_TK_LINED    (13)
#define   LEX_TK_FILED    (14)



/* 定义 指令 的词法编码。 */


#define  INS_SAVE     0x01        // 0xfa004001
#define  INS_UNSAVE   0x02        // 0xfb200001
#define  INS_POP      0x03        // 0xf8000401
#define  INS_SYNC     0x04        // 0xfc000002
#define  INS_RESUME   0x05        // 0xf9400002
#define  INS_JMP      0x06        // 0xf000000C
#define  INS_FIX      0x07        // 0x05000010
#define  INS_FIXU     0x08        // 0x07000010
#define  INS_FLOT     0x09        // 0x08000010
#define  INS_FINT     0x0A        // 0x17000010
#define  INS_FLOTU    0x0B        // 0x0a000010
#define  INS_FSQRT    0x0C        // 0x15000010
#define  INS_SFLOT    0x0D        // 0x0c000010
#define  INS_SFLOTU   0x0E        // 0x0e000010
#define  INS_GET      0x0F        // 0xfe002020
#define  INS_SETH     0x10        // 0xe0000040
#define  INS_SETL     0x11        // 0xe3000040
#define  INS_SETMH    0x12        // 0xe1000040
#define  INS_SETML    0x13        // 0xe2000040
#define  INS_INCH     0x14        // 0xe4000040
#define  INS_INCL     0x15        // 0xe7000040
#define  INS_INCMH    0x16        // 0xe5000040
#define  INS_INCML    0x17        // 0xe6000040
#define  INS_ORH      0x18        // 0xe8000040
#define  INS_ORL      0x19        // 0xeb000040
#define  INS_ORMH     0x1A        // 0xe9000040
#define  INS_ORML     0x1B        // 0xea000040
#define  INS_ANDH     0x1C        // 0xec000040
#define  INS_ANDL     0x1D        // 0xef000040
#define  INS_ANDMH    0x1E        // 0xed000040
#define  INS_ANDML    0x1F        // 0xee000040
#define  INS_BN       0x20        // 0x40000180
#define  INS_BP       0x21        // 0x44000180
#define  INS_BZ       0x22        // 0x42000180
#define  INS_BEV      0x23        // 0x4e000180
#define  INS_BNN      0x24        // 0x48000180
#define  INS_BNP      0x25        // 0x4c000180
#define  INS_BNZ      0x26        // 0x4a000180
#define  INS_BOD      0x27        // 0x46000180
#define  INS_PBN      0x28        // 0x50000180
#define  INS_PBP      0x29        // 0x54000180
#define  INS_PBZ      0x2A        // 0x52000180
#define  INS_PBEV     0x2B        // 0x5e000180
#define  INS_PBNN     0x2C        // 0x58000180
#define  INS_PBNP     0x2D        // 0x5c000180
#define  INS_PBNZ     0x2E        // 0x5a000180
#define  INS_PBOD     0x2F        // 0x56000180
#define  INS_PUSHJ    0x30        // 0xf2000180
#define  INS_GETA     0x31        // 0xf4000180
#define  INS_PUT      0x32        // 0xf6860200
//#define  INS_POP      0x03      //   0xf8000401
#define  INS_MUL      0x33        // 0x18001800
#define  INS_MULU     0x34        // 0x1a001800
#define  INS_DIV      0x35        // 0x1c001800
#define  INS_DIVU     0x36        // 0x1e001800
#define  INS_ADD      0x37        // 0x20001800
#define  INS_ADDU     0x38        // 0x22001800
#define  INS_SUB      0x39        // 0x24001800
#define  INS_SUBU     0x3A        // 0x26001800
#define  INS_2ADDU    0x3B        // 0x28001800
#define  INS_4ADDU    0x3C        // 0x2a001800
#define  INS_8ADDU    0x3D        // 0x2c001800
#define  INS_16ADDU   0x3F        // 0x2e001800
#define  INS_CMP      0x40        // 0x30001800
#define  INS_CMPU     0x41        // 0x32001800
#define  INS_NEG      0x42        // 0x34001800
#define  INS_NEGU     0x43        // 0x36001800
#define  INS_SL       0x44        // 0x38001800
#define  INS_SLU      0x45        // 0x3a001800
#define  INS_SR       0x46        // 0x3c001800
#define  INS_SRU      0x47        // 0x3e001800
#define  INS_CSN      0x48        // 0x60001800
#define  INS_CSP      0x49        // 0x64001800
#define  INS_CSZ      0x4A        // 0x62001800
#define  INS_CSNN     0x4B        // 0x68001800
#define  INS_CSNP     0x4C        // 0x6c001800
#define  INS_CSNZ     0x4D        // 0x6a001800
#define  INS_CSOD     0x4E        // 0x66001800
#define  INS_CSEV     0x4F        // 0x6e001800
#define  INS_ZSN      0x50        // 0x70001800
#define  INS_ZSP      0x51        // 0x74001800
#define  INS_ZSZ      0x52        // 0x72001800
#define  INS_ZSEV     0x53        // 0x7e001800
#define  INS_ZSNN     0x54        // 0x78001800
#define  INS_ZSNP     0x55        // 0x7c001800
#define  INS_ZSNZ     0x56        // 0x7a001800
#define  INS_ZSOD     0x57        // 0x76001800
#define  INS_LDB      0x58        // 0x80001800
#define  INS_LDBU     0x59        // 0x82001800
#define  INS_LDW      0x5A        // 0x84001800
#define  INS_LDWU     0x5B        // 0x86001800
#define  INS_LDT      0x5C        // 0x88001800
#define  INS_LDTU     0x5D        // 0x8a001800
#define  INS_LDO      0x5E        // 0x8c001800
#define  INS_LDOU     0x5F        // 0x8e001800
#define  INS_LDHT     0x5F        // 0x92001800
#define  INS_LDSF     0x60        // 0x90001800
#define  INS_CSWAP    0x61        // 0x94001800
#define  INS_LDUNC    0x62        // 0x96001800
#define  INS_LDVTS    0x63        // 0x98001800
#define  INS_STUNC    0x64        // 0xb6001800
#define  INS_GO       0x65        // 0x9e001800
#define  INS_OR       0x66        // 0xc0001800
#define  INS_ORN      0x67        // 0xc2001800
#define  INS_AND      0x68        // 0xc8001800
#define  INS_XOR      0x69        // 0xc6001800
#define  INS_NOR      0x6A        // 0xc4001800
#define  INS_ANDN     0x6B        // 0xca001800
#define  INS_NAND     0x6C        // 0xcc001800
#define  INS_NXOR     0x6D        // 0xce001800
#define  INS_BDIF     0x6E        // 0xd0001800
#define  INS_WDIF     0x6F        // 0xd2001800
#define  INS_TDIF     0x70        // 0xd4001800
#define  INS_ODIF     0x71        // 0xd6001800
#define  INS_MUX      0x72        // 0xd8001800
#define  INS_SADD     0x73        // 0xda001800
#define  INS_MOR      0x74        // 0xdc001800
#define  INS_MXOR     0x75        // 0xde001800
#define  INS_STB      0x76        // 0xa0001800
#define  INS_STBU     0x77        // 0xa2001800
#define  INS_STW      0x78        // 0xa4001800
#define  INS_STWU     0x79        // 0xa6001800
#define  INS_STT      0x7A        // 0xa8001800
#define  INS_STTU     0x7B        // 0xaa001800
#define  INS_STO      0x7C        // 0xac001800
#define  INS_STOU     0x7D        // 0xae001800
#define  INS_STHT     0x7E        // 0xb2001800
#define  INS_STSF     0x7F        // 0xb0001800
#define  INS_SYNCD    0x80        // 0xb8001800
#define  INS_SYNCID   0x81        // 0xbc001800
#define  INS_PUSHGO   0x82        // 0xbe001800
#define  INS_FCMP     0x83        // 0x01001000
#define  INS_FUN      0x84        // 0x02001000
#define  INS_FEQL     0x85        // 0x03001000
#define  INS_FADD     0x86        // 0x04001000
#define  INS_FSUB     0x87        // 0x06001000
#define  INS_FDIV     0x88        // 0x14001000
#define  INS_FMUL     0x89        // 0x10001000
#define  INS_FCMPE    0x8A        // 0x11001000
#define  INS_FEQLE    0x8B        // 0x13001000
#define  INS_FUNE     0x8C        // 0x12001000
#define  INS_FREM     0x8D        // 0x16001000
//#define  INS_GET      0x0F      //   0xfe002020
//#define  INS_SAVE     0x01      //   0xfa004001
//#define  INS_PUT      0x28      //   0xf6860200
#define  INS_STCO     0x8E        // 0xb4180000
#define  INS_PREGO    0x8F        // 0x9c180000
#define  INS_PRELD    0x90        // 0x9a180000
#define  INS_PREST    0x91        // 0xba180000
//#define  INS_UNSAVE   0x02      //   0xfb200001
#define  INS_SWYM     0x92        // 0xfd400000
#define  INS_TRAP     0x93        // 0x00400000
#define  INS_TRIP     0x94        // 0xff400000
//#define  INS_RESUME   0x05      //   0xf9400002
//#define  INS_PUT      0x32      //   0xf6860200



                         
/* 定义 命令 的词法编码。 */

#define  CMD_BYTE          0x00
#define  CMD_WYDE          0x01
#define  CMD_TETRA         0x02
#define  CMD_OCTA          0x03
                           
#define  CMD_SINGLE        0x04
#define  CMD_DOUBLE        0x05
                           
#define  CMD_LOCAL         0x06
#define  CMD_WEAK          0x07
#define  CMD_GLOBAL        0x08
#define  CMD_EXTERN        0x09
                           
#define  CMD_PARAM         0x0A
#define  CMD_ALIGN         0x0B
#define  CMD_SECTION       0x0C
                           
#define  CMD_RES_BYTE      0x0D
#define  CMD_RES_WYDE      0x0E
#define  CMD_RES_TETRA     0x0F
#define  CMD_RES_OCTA      0x10
#define  CMD_RES_SINGLE    0x11
#define  CMD_RES_DOUBLE    0x12
                           
#define  CMD_STR_ASCII     0x13
#define  CMD_STR_UTF8      0x14
#define  CMD_STR_UTF16     0x15
#define  CMD_STR_UTF32     0x16
#define  CMD_STR_GB2312    0x17
#define  CMD_STR_GB18030   0x18


/* 定义 常量 的词法编码。 */
#define  CNT_SYS           0x00
#define  CNT_UP            0x01
#define  CNT_DOWN          0x02
#define  CNT_NEAR          0x03
#define  CNT_OFF           0x04

#define  CNT_TEXT          0x05
#define  CNT_DATA          0x06
#define  CNT_BSS           0x07
#define  CNT_NOTE          0x08

#define  CNT_ZERO          0x09
#define  CNT_SNAN          0x0A
#define  CNT_QNAN          0x0B
#define  CNT_INFINITE      0x0C
#define  CNT_DENORMAL      0x0D



/*  定义 特殊寄存器 的词法编码  */
#define  SRG_rA          (21)
#define  SRG_rB          (0 )
#define  SRG_rC          (8 )
#define  SRG_rD          (1 )
#define  SRG_rE          (2 )
#define  SRG_rF          (22)
#define  SRG_rG          (19)
#define  SRG_rH          (3 )
#define  SRG_rI          (12)
#define  SRG_rJ          (4 )
#define  SRG_rK          (15)
#define  SRG_rL          (20)
#define  SRG_rM          (5 )
#define  SRG_rN          (9 )
#define  SRG_rO          (10)
#define  SRG_rP          (23)
#define  SRG_rQ          (16)
#define  SRG_rR          (6 )
#define  SRG_rS          (11)
#define  SRG_rT          (13)
#define  SRG_rU          (17)
#define  SRG_rV          (18)
#define  SRG_rW          (24)
#define  SRG_rX          (25)
#define  SRG_rY          (26)
#define  SRG_rZ          (27)
#define  SRG_rBB         (7 )
#define  SRG_rTT         (14)
#define  SRG_rWW         (28)
#define  SRG_rXX         (29)
#define  SRG_rYY         (30)
#define  SRG_rZZ         (31)


#define   LEX_TOKEN_MAX_LEN   (128)

typedef  struct
{
    /* 被 lex 解析过的信息. */
    tetra  type;
    tetra  info;
    
    octa   valint;
    double valflt;

    /* 字符串信息..*/
    tetra  eat;
    tetra  len;
    tetra  str[LEX_TOKEN_MAX_LEN];
    
}  lex_token_t;



tetra  le_init_context( tetra  pin );
void  le_fini_context( tetra plex );
void  le_next_token( tetra plex, lex_token_t * ptoken );

#endif



